****Main Do-File for Tables***
		
		
												*Replication file for Tables in "The Long-Run Educational Benefits of High-Achieving Classrooms"

**Combine 2015, 2016 2017 cohorts into one.
use "C:\Users\X\2015data.dta"
gen year=2015
append using "C:\Users\X\2016data.dta", force
replace year =2016 if year==.
append using "C:\Users\X\2017data.dta", force
replace year =2017 if year==.
*drop undidentified IDs
drop if unique_ID==99999
*genrate new uniques ID so IDs dont overlap in both datasetss
gen newID = unique_ID*year

*Generate running variable for RD*
gen running = Total_mark if Exam==1
bys newID: egen running1 = mean(running)

*Normalize cutoffs by year
*Year 2017 cutoff
gen normrunning = running1-425 if year==2017 
*year 2016 cutoff
replace normrunning = running1-467 if year==2016 
* Year 2015 cutoff 
replace normrunning = running1-480 if year==2015  

*Need to make changes to year 2017 top classroom which has coding error (top_class==2)
replace Top_class = 0 if Top_class==2 & year==2017

*generate Gender dummy
destring Gender, gen(sex) force
*gen dummies for each year
tab year, gen(years)


*Generate bins for RD graphs
gen bin=.
	
quietly forvalues j = 0 (5) 75 {
replace bin=`j'+2.5 if normrunning>=`j' & normrunning<`j'+5
} 

quietly forvalues j = -75 (5) -5 {
replace bin=`j'+2.5 if normrunning>=`j' & normrunning<`j'+5
} 



*Generating high school entrance scores in main subjects (Math, English and Chinese) as control*
gen hsscore1 = Chinese + Math + English if Exam==0
*Below is to replace missing with whatever score we have
replace hsscore1 = Total_mark if Exam==0 & hsscore1==.
bys newID: egen hsscore = mean(hsscore1)

**Note to use first stage in first year of high school (since can be in different section in third year)
gen Top_classsec = Top_class if Exam==1
bys newID: egen Top_class1 = mean(Top_classsec)

*Variables for Regressions
  gen treatment = 1 if normrunning >=0 & normrunning!=.
replace treatment = 0 if normrunning <0
gen slope = normrunning*treatment

*Generate urban versus rural variable*
bys newID: egen urban2 = mean(urban)
replace urban2 = 0 if urban2==.
drop urban
ren urban2 urban


*Identifying average student composition in school and track**
sum  Total_mark if Exam==0 & year==2017
sum  Total_mark if Exam==0 & year==2017 & Top_class==1


	*A) Generate Standardized GAOKAO EXAM RESULTS
  
  *Creating standardized variables (By track)
   egen stgaok1sci = std(Total_mark) if Exam==99 & year==2015  & Division==1
		egen stgaok2sci = std(Total_mark) if Exam==99 & year==2016 & Division==1
	egen stgaok3sci = std(Total_mark) if Exam==99 & year==2017 & Division==1

	gen stgaok = stgaok1sci
			replace stgaok = stgaok2sci if year==2016 & Division==1
	replace stgaok = stgaok3sci if year==2017  & Division==1
	
	*Arts
	  egen stgaok1art = std(Total_mark) if Exam==99 & year==2015  & Division==0
		egen stgaok2art = std(Total_mark) if Exam==99 & year==2016 & Division==0
	egen stgaok3art = std(Total_mark) if Exam==99 & year==2017 & Division==0

	replace stgaok = stgaok1art if year==2015 & Division==0
		replace stgaok = stgaok2art  if year==2016  &  Division==0
	replace stgaok = stgaok3art if year==2017  & Division==0
	
	
	
		
	* Generate Variable for Likelihood of going to any Chinese college
						*checking if college outcome missing
		bys newID: egen maxcoll1 = mean(if_FirstBatch) 
				gen College1 = 1 if Exam==99 
						replace College1 = 0 if Exam==99 & maxcoll==.
						
						
	* Generate Variable for First tier Univisty attendance (widest definition)
gen firsttieradmit = 1 if if_FirstBatch==1
replace firsttieradmit = 0 if if_FirstBatch!= 1



**2)  Generate Top 100 (211 project) Univisty attendance (2nd widest definition)
*Fixing errors with 211 schools (those who didnt enter first_tier). This is instnce where someone is in top 100 but not intop tier (which shouldnt be possible)

replace if_211 = 0 if newID == 1100736 & Exam==99
replace if_211 = 0 if newID == 62496 & Exam==99
replace if_211 = 0 if newID == 429408 & Exam==99
	
gen top100admit = 1 if if_211==1
replace top100admit = 0 if if_211!=1


	**3)  Generate  Top 40 (985 project) Univisty attendance (3rd widest definition)
		*Fixing errors with 985 schools (those who didnt enter first_tier). This is instnce where someone is in top 40 but not in something less ranked (which shouldnt be possible)
		replace if_985 =0 if if_985==1 & if_211==0
		
gen top40admit = 1 if if_985==1
replace top40admit = 0 if if_985!=1 



exit




		*****************************************************************************************************************************************
		***************************************Table 1----------Summary Statistics***************************************************************
		*****************************************************************************************************************************************

		*** Standardized High School test scores years 1 through 3
	bys newID: egen firstyearscore = mean(Total_mark) if Exam==12 | Exam==13 | Exam==14 | Exam==15 | Exam==16 | Exam==17 
	

		*Standardized by year**
		egen st1 = std(firstyearscore) if year==2015 
		egen st2 = std(firstyearscore) if year==2016 
		egen st3 = std(firstyearscore) if year==2017 
		
		gen st = st1 
		replace st = st2 if year==2016
		replace st = st3 if year==2017
		
		

	bys newID: egen secondyearscore= mean(Total_mark) if Exam==21 | Exam==22 | Exam==23 | Exam==24 | Exam==25 | Exam==26 
	
			egen st11 = std(secondyearscore) if year==2015
		egen st21 = std(secondyearscore) if year==2016
		egen st31 = std(secondyearscore) if year==2017
		
		gen st22 = st11 
		replace st22 = st21 if year==2016
		replace st22 = st31 if year==2017
		
	
bys newID: egen thirdyearscore = mean(Total_mark) if Exam==31 | Exam==32 | Exam==33 | Exam==34 | Exam==35 | Exam==36 | Exam==37 

	
		egen st111 = std(thirdyearscore) if year==2015
		egen st211 = std(thirdyearscore) if year==2016
		egen st311 = std(thirdyearscore) if year==2017
		
		gen st33 = st111
		replace st33 = st211 if year==2016
		replace st33 = st311 if year==2017
		
*attrition, i.e. likliehood of not taking Gaokao exam*
		
		bys newID: egen maxfax = max(Exam) 
				gen missing = 0 if Exam==11
						replace missing = 1 if Exam==11 & maxfax!=99	
						
					
		
		****A- INDIVIDUAL LEVEL SUMMARY STATS******
**Full Sample followed by marginal sample
**High school entrance score
sum Total_mark if Exam==0 & hsscore!=. 
sum Total_mark if Exam==0 & hsscore!=.  & normrunning<=75 & normrunning>=-75
**Track Exam Score
sum Total_mark if Exam==1 & hsscore!=. 
sum Total_mark if Exam==1 & hsscore!=.  & normrunning<=75 & normrunning>=-75
**College entrance exam score (Science)
sum Total_mark if Exam==99 & hsscore!=. & Division==1
sum Total_mark if Exam==99 & hsscore!=.  & normrunning<=75 & normrunning>=-75 & Division==1
**College entrance exam score (Arts)
sum Total_mark if Exam==99 & hsscore!=. & Division==0
sum Total_mark if Exam==99 & hsscore!=.  & normrunning<=75 & normrunning>=-75 & Division==0
**Proportion in Top_track
sum Top_class if Exam==1 & hsscore!=.
sum Top_class if Exam==1 & hsscore!=.  & normrunning<=75 & normrunning>=-75
***First Year test scores (Standardized) (Need to remove restriction for standardization)
sum st if Exam==12  
sum st if Exam==12  & normrunning<=75 & normrunning>=-75
***Second Year test scores (Standardized) 
sum st22 if Exam==21 
sum st22 if Exam==21   & normrunning<=75 & normrunning>=-75
***Third Year test scores  (Standardized) 
sum st33 if Exam==31 
sum st33 if Exam==31  & normrunning<=75 & normrunning>=-75
**Proportion Male*
sum sex if Exam==1 & hsscore!=.
sum sex if Exam==1 & hsscore!=.  & normrunning<=75 & normrunning>=-75
**Proportion urban*
sum urban if Exam==1 & hsscore!=.
sum urban if Exam==1 & hsscore!=.  & normrunning<=75 & normrunning>=-75
**Selecting Science Track*
sum Division if Exam==21 & hsscore!=.
sum Division if Exam==21 & hsscore!=.  & normrunning<=75 & normrunning>=-75
**Proportion not taking College Entrance Exam*
sum missing if Exam==11 & hsscore!=.
sum missing if Exam==11 & hsscore!=.  & normrunning<=75 & normrunning>=-75
**Proportion  enrolled in any Chinese University*
sum College1 if Exam==99 & hsscore!=.
sum College1 if Exam==99 & hsscore!=.  & normrunning<=75 & normrunning>=-75
**Top_tier University
sum firsttieradmit if Exam==99 & hsscore!=. 
sum firsttieradmit if Exam==99 & hsscore!=.  & normrunning<=75 & normrunning>=-75
**Top 100 University
sum top100admit if Exam==99 & hsscore!=. 
sum top100admit if Exam==99 & hsscore!=.  & normrunning<=75 & normrunning>=-75
**Top 40 University
sum top40admit if Exam==99 & hsscore!=. 
sum top40admit if Exam==99 & hsscore!=.  & normrunning<=75 & normrunning>=-75

**Class Level Variables (Over all three years. Note that mechanisms section is only for first year classes)**

preserve
	keep if Exam==0 | Exam==21 | Exam==31
	bys Class year Exam: gen classsize = _N if Class!="."
	
	sum classsize  if  hsscore!=.
		sum classsize  if hsscore!=.  & normrunning<=75 & normrunning>=-75

**NOTE : TO GET TOTAL NUMBER OF CLASSES JUST TAB CLASS BY YEAR

	restore
	

	
	
		*****************************************************************************************************************************************
		***************************************Table 2----------First Stage***************************************************************
		*****************************************************************************************************************************************
		
		
		*CCT Bandwidth (Note alwas use triangular kernel with controls to determine optimal bandwidth)
				
		*Triangular CCT without controls*		
		rdrobust Top_class normrunning if Exam==1 & hsscore!=.,  h( 52.619      17.219)
		*Uniform CCT without controls*		
		rdrobust Top_class normrunning if Exam==1 & hsscore!=.,  h( 52.619      17.219) kernel(uni)
		
		
		*Triangular CCT with controls*(use this to pick bandwidths)	
		rdrobust Top_class normrunning if Exam==1 & hsscore!=., covs(years1 years2 ) bwselect ( msetwo )
		*Uniform CCT with controls*		
		rdrobust Top_class normrunning if Exam==1 & hsscore!=., covs(years1 years2 ) h(  52.619      17.219) kernel(uni)

			
			
		*****************************************************************************************************************************************
		********************************************************Table 3---First Three Year High school scores *******************************************************
		*****************************************************************************************************************************************

			
			
		
		*CCT Bandwidth (Note alwas use triangular kernel with controls to determine optimal bandwidth)
				
				***PANEL A****************************1st Year Performance (exclude first exam)***************************************

		*A) Standardized MATH Scores

	bys newID: egen firstyearMath = mean(Math) if Exam==12 | Exam==13 | Exam==14 | Exam==15 | Exam==16 | Exam==17 
	
		egen stmat1 = std(firstyearMath) if year==2015
		egen stmat2 = std(firstyearMath) if year==2016
		egen stmat3 = std(firstyearMath) if year==2017
		
		gen stmath = stmat1
		replace stmath = stmat2 if year==2016
		replace stmath = stmat3 if year==2017

		
		*Triangular CCT without controls*		
		rdrobust stmath normrunning if Exam==12 & hsscore!=.,  h(     47.906      25.388)
		estimates store reg1

		*Uniform CCT without controls*		
		rdrobust stmath normrunning if Exam==12 & hsscore!=.,  h(      47.906      25.388) kernel(uni)
				estimates store reg2



		
		*Triangular CCT with controls*(use this to pick bandwidths)	
		rdrobust stmath normrunning if Exam==12 & hsscore!=., covs(sex years1 years2 hsscore urban ) bwselect ( msetwo )
						estimates store reg3 

		*Uniform CCT with controls*		
		rdrobust stmath normrunning if Exam==12 & hsscore!=., covs(sex years1 years2 hsscore urban ) h(   47.906      25.388) kernel(uni)
						estimates store reg4 
		
			estout reg* using test.tex, replace cells(b(fmt(%9.3f) star label(Coef.)) se(fmt(%9.3f) par label(Std)))  starlevels(* 0.1 ** 0.05 *** 0.01) stats(N_h_l N_h_r, fmt(%9.0f) label(Eff. Number of obs)) style(tex)  
			
			
			*B) Standardized Chinese Scores

			bys newID: egen firstyearChinese = mean(Chinese) if Exam==12 | Exam==13 | Exam==14 | Exam==15 | Exam==16 | Exam==17 
			
					egen stchi1 = std(firstyearChinese) if year==2015
		egen stchi2 = std(firstyearChinese) if year==2016
		egen stchi3 = std(firstyearChinese) if year==2017
		
		gen stChinese = stchi1 
		replace stChinese = stchi2 if year==2016
		replace stChinese = stchi3 if year==2017
		
				*Triangular CCT without controls*		
		rdrobust stChinese normrunning if Exam==12 & hsscore!=.,  h(    40.189      25.437)
								estimates store reg1

		*Uniform CCT without controls*		
		rdrobust stChinese normrunning if Exam==12 & hsscore!=., h(     40.189      25.437) kernel(uni)
								estimates store reg2

		
		
		*Triangular CCT with controls*(use this to pick bandwidths)	
		rdrobust stChinese normrunning if Exam==12 & hsscore!=., covs(sex years1 years2 hsscore urban ) bwselect ( msetwo )
								estimates store reg3
		*Uniform CCT with controls*		
		rdrobust stChinese normrunning if Exam==12 & hsscore!=., covs(sex years1 years2 hsscore urban )h(      40.189      25.437) kernel(uni)
								estimates store reg4
								
								estout reg* using test.tex, replace cells(b(fmt(%9.3f) star label(Coef.)) se(fmt(%9.3f) par label(Std)))  starlevels(* 0.1 ** 0.05 *** 0.01) stats(N_h_l N_h_r, fmt(%9.0f) label(Eff. Number of obs)) style(tex)
		
				*C) Standardized English scores
			
	bys newID: egen firstyearEnglish = mean(English) if  Exam==12 | Exam==13 | Exam==14 | Exam==15 | Exam==16 | Exam==17 
	
	
		egen steng1 = std(firstyearEnglish) if year==2015
		egen steng2 = std(firstyearEnglish) if year==2016
		egen steng3 = std(firstyearEnglish) if year==2017
		
		gen stenglish = steng1 
		replace stenglish = steng2 if year==2016
		replace stenglish = steng3 if year==2017
			
			
						*Triangular CCT without controls*		
		rdrobust  stenglish normrunning if Exam==12 & hsscore!=.,  h(  54.962      17.403)
										estimates store reg1

		*Uniform CCT without controls*		
		rdrobust  stenglish normrunning if Exam==12 & hsscore!=.,  h(  54.962      17.403) kernel(uni)
										estimates store reg2

		
		
		*Triangular CCT with controls*(use this to pick bandwidths)	
		rdrobust  stenglish normrunning if Exam==12 & hsscore!=., covs(sex years1 years2 hsscore urban) bwselect ( msetwo )
										estimates store reg3

		*Uniform CCT with controls*		
		rdrobust  stenglish normrunning if Exam==12 & hsscore!=., covs(sex years1 years2 hsscore urban ) h(  54.962      17.403) kernel(uni)
										estimates store reg4

		estout reg* using test.tex, replace cells(b(fmt(%9.3f) star label(Coef.)) se(fmt(%9.3f) par label(Std)))  starlevels(* 0.1 ** 0.05 *** 0.01) stats(N_h_l N_h_r, fmt(%9.0f) label(Eff. Number of obs)) style(tex)
		
			*CCT Bandwidth (Note alwas use triangular kernel with controls to determine optimal bandwidth)
				
				 
				 
				 *****************************PANEL B******2nd Year Performance***************************************

		*A) Standardized MATH Scores

bys newID: egen secondyearMath = mean(Math) if Exam==21 | Exam==22 | Exam==23 | Exam==24 | Exam==25 | Exam==26 

	
		egen stmat11sci = std(secondyearMath) if year==2015  & Division==1
		egen stmat21sci = std(secondyearMath) if year==2016  & Division==1
		egen stmat31sci = std(secondyearMath) if year==2017  & Division==1
		
			egen stmat11art = std(secondyearMath) if year==2015  & Division==0
		egen stmat21art = std(secondyearMath) if year==2016  & Division==0
		egen stmat31art = std(secondyearMath) if year==2017  & Division==0
		
		gen stmath2 = stmat11sci
		replace stmath2 = stmat21sci if year==2016 & Division==1
		replace stmath2 = stmat31sci if year==2017 & Division==1
			replace stmath2 = stmat11art if year==2015 & Division==0
		replace stmath2 = stmat21art if year==2016 & Division==0
			replace stmath2 = stmat31art if year==2017 & Division==0
		

		
		*Triangular CCT without controls*		
		rdrobust stmath2 normrunning if Exam==21 & hsscore!=.,  h(   37.041      18.660)
												estimates store reg1

		
		*Uniform CCT without controls*		
		rdrobust stmath2 normrunning if Exam==21 & hsscore!=.,  h(  37.041      18.660) kernel(uni)
												estimates store reg2
		
		
		*Triangular CCT with controls*(use this to pick bandwidths)	
		rdrobust stmath2 normrunning if Exam==21 & hsscore!=., covs(sex years1 years2 hsscore urban ) bwselect ( msetwo )
												estimates store reg3

		*Uniform CCT with controls*		
		rdrobust stmath2 normrunning if Exam==21 & hsscore!=., covs(sex years1 years2 hsscore urban ) h(   37.041      18.660) kernel(uni)
												estimates store reg4

		
		
		
		estout reg* using test.tex, replace cells(b(fmt(%9.3f) star label(Coef.)) se(fmt(%9.3f) par label(Std)))  starlevels(* 0.1 ** 0.05 *** 0.01) stats(N_h_l N_h_r, fmt(%9.0f) label(Eff. Number of obs)) style(tex)
		
		*B) Standardized Chinese Scores
			
	
		bys newID: egen secondyearChi = mean(Chi) if Exam==21 | Exam==22 | Exam==23 | Exam==24 | Exam==25 | Exam==26 

	
		egen stchi11sci = std(secondyearChi) if year==2015  & Division==1
		egen stchi21sci = std(secondyearChi) if year==2016  & Division==1
		egen stchi31sci = std(secondyearChi) if year==2017  & Division==1
		
			egen stchi11art = std(secondyearChi) if year==2015  & Division==0
		egen stchi21art = std(secondyearChi) if year==2016  & Division==0
		egen stchi31art = std(secondyearChi) if year==2017  & Division==0
		
		gen stChi2 = stchi11sci
		replace stChi2 = stchi21sci if year==2016 & Division==1
		replace stChi2 = stchi31sci if year==2017 & Division==1
			replace stChi2 = stchi11art if year==2015 & Division==0
		replace stChi2 = stchi21art if year==2016 & Division==0
			replace stChi2 = stchi31art if year==2017 & Division==0
		
				*Triangular CCT without controls*		
		rdrobust stChi2 normrunning if Exam==21 & hsscore!=.,  h( 32.892      20.656)
														estimates store reg1

		*Uniform CCT without controls*		
		rdrobust stChi2 normrunning if Exam==21 & hsscore!=., h(  32.892      20.656) kernel(uni)
														estimates store reg2

		
		
		*Triangular CCT with controls*(use this to pick bandwidths)	
		rdrobust stChi2 normrunning if Exam==21 & hsscore!=., covs(sex years1 years2 hsscore urban ) bwselect ( msetwo )
														estimates store reg3

		*Uniform CCT with controls*		
		rdrobust stChi2 normrunning if Exam==21 & hsscore!=., covs(sex years1 years2 hsscore urban )h(  32.892      20.656) kernel(uni)
														estimates store reg4

		
		
				estout reg* using test.tex, replace cells(b(fmt(%9.3f) star label(Coef.)) se(fmt(%9.3f) par label(Std)))  starlevels(* 0.1 ** 0.05 *** 0.01) stats(N_h_l N_h_r, fmt(%9.0f) label(Eff. Number of obs)) style(tex)
		
			**C) Standardized English Scores

					
	bys newID: egen secondyearEng = mean(English) if Exam==21 | Exam==22 | Exam==23 | Exam==24 | Exam==25 | Exam==26 

	
		egen stEng11sci = std(secondyearEng) if year==2015  & Division==1
		egen stEng21sci = std(secondyearEng) if year==2016  & Division==1
		egen stEng31sci = std(secondyearEng) if year==2017  & Division==1
		
			egen stEng11art = std(secondyearEng) if year==2015  & Division==0
		egen stEng21art = std(secondyearEng) if year==2016  & Division==0
		egen stEng31art = std(secondyearEng) if year==2017  & Division==0
		
		gen stEng2 = stEng11sci
		replace stEng2 = stEng21sci if year==2016 & Division==1
		replace stEng2 = stEng31sci if year==2017 & Division==1
			replace stEng2 = stEng11art if year==2015 & Division==0
		replace stEng2 = stEng21art if year==2016 & Division==0
			replace stEng2 = stEng31art if year==2017 & Division==0
			
						*Triangular CCT without controls*		
		rdrobust  stEng2  normrunning if Exam==21 & hsscore!=.,  h(    49.218      19.913)
														estimates store reg1
		*Uniform CCT without controls*		
		rdrobust  stEng2  normrunning if Exam==21 & hsscore!=.,  h(     49.218      19.913) kernel(uni)
														estimates store reg2

		
		
		*Triangular CCT with controls*(use this to pick bandwidths)	
		rdrobust  stEng2  normrunning if Exam==21 & hsscore!=., covs(sex years1 years2 hsscore urban ) bwselect ( msetwo )
														estimates store reg3

		*Uniform CCT with controls*		
		rdrobust  stEng2  normrunning if Exam==21 & hsscore!=., covs(sex years1 years2 hsscore urban ) h(    49.218      19.913) kernel(uni)
														estimates store reg4

		
		
				estout reg* using test.tex, replace cells(b(fmt(%9.3f) star label(Coef.)) se(fmt(%9.3f) par label(Std)))  starlevels(* 0.1 ** 0.05 *** 0.01) stats(N_h_l N_h_r, fmt(%9.0f) label(Eff. Number of obs)) style(tex)
		
		
		
				
				 *****************************PANEL C******3rd Year Performance ***************************************

			**A) Standardized Math Scores

bys newID: egen thirdyearMath = mean(Math) if Exam==31 | Exam==32 | Exam==33 | Exam==34 | Exam==35 | Exam==36 | Exam==37 

	
		egen stmat111sci = std(thirdyearMath) if year==2015 & Division==1
		egen stmat211sci = std(thirdyearMath) if year==2016 & Division==1
		egen stmat311sci = std(thirdyearMath) if year==2017 & Division==1
		
				egen stmat111art = std(thirdyearMath) if year==2015 & Division==0
		egen stmat211art = std(thirdyearMath) if year==2016 & Division==0
		egen stmat311art = std(thirdyearMath) if year==2017 & Division==0
		

		gen stmath3 = stmat111sci
		replace stmath3 = stmat211sci if year==2016 & Division==1
		replace stmath3 = stmat311sci if year==2017 & Division==1
		
			replace stmath3 = stmat111art if year==2015 & Division==0
		replace stmath3 = stmat211art if year==2016 & Division==0
			replace stmath3 = stmat311art if year==2017 & Division==0
  

		
		*Triangular CCT without controls*		
		rdrobust stmath3 normrunning if Exam==31 & hsscore!=.,  h(35.051      19.530)
					estimates store reg1
		*Uniform CCT without controls*		
		rdrobust stmath3 normrunning if Exam==31 & hsscore!=.,  h( 35.051      19.530) kernel(uni)
					estimates store reg2
		
		
		*Triangular CCT with controls*(use this to pick bandwidths)	
		rdrobust stmath3 normrunning if Exam==31 & hsscore!=., covs(sex years1 years2 hsscore urban ) bwselect ( msetwo )
					estimates store reg3

		*Uniform CCT with controls*		
		rdrobust stmath3 normrunning if Exam==31 & hsscore!=., covs(sex years1 years2 hsscore urban) h( 35.051      19.530) kernel(uni)
			estimates store reg4

		
		
				estout reg* using test.tex, replace cells(b(fmt(%9.3f) star label(Coef.)) se(fmt(%9.3f) par label(Std)))  starlevels(* 0.1 ** 0.05 *** 0.01) stats(N_h_l N_h_r, fmt(%9.0f) label(Eff. Number of obs)) style(tex)
		
		
		
			**B) Standardized Chinese Scores
			
	bys newID: egen thirdyearChi= mean(Chinese) if Exam==31 | Exam==32 | Exam==33 | Exam==34 | Exam==35 | Exam==36  | Exam==37
	
				egen stchi111sci = std(thirdyearChi) if year==2015 & Division==1
		egen stchi211sci = std(thirdyearChi) if year==2016 & Division==1
		egen stchi311sci = std(thirdyearChi) if year==2017 & Division==1
		
						egen stchi111art = std(thirdyearChi) if year==2015 & Division==0
		egen stchi211art = std(thirdyearChi) if year==2016 & Division==0
		egen stchi311art = std(thirdyearChi) if year==2017 & Division==0
		
		gen stChinese3 = stchi111sci 
		replace stChinese3 = stchi211sci if year==2016 & Division==1
		replace stChinese3 = stchi311sci if year==2017 & Division==1

				replace stChinese3 = stchi111art if year==2015 & Division==0
		replace stChinese3 = stchi211art if year==2016 & Division==0
				replace stChinese3 = stchi311art if year==2017 & Division==0

		
				*Triangular CCT without controls*		
		rdrobust stChinese3 normrunning if Exam==31 & hsscore!=.,  h( 35.634      15.612)
				estimates store reg1
		*Uniform CCT without controls*		
		rdrobust stChinese3 normrunning if Exam==31 & hsscore!=., h( 35.634      15.612) kernel(uni)
				estimates store reg2
		
		
		*Triangular CCT with controls*(use this to pick bandwidths)	
		rdrobust stChinese3 normrunning if Exam==31 & hsscore!=., covs(sex years1 years2 hsscore urban ) bwselect ( msetwo )
				estimates store reg3
		*Uniform CCT with controls*		
		rdrobust stChinese3 normrunning if Exam==31 & hsscore!=., covs(sex years1 years2 hsscore urban)h( 35.634      15.612) kernel(uni)
		estimates store reg4

		
		
				estout reg* using test.tex, replace cells(b(fmt(%9.3f) star label(Coef.)) se(fmt(%9.3f) par label(Std)))  starlevels(* 0.1 ** 0.05 *** 0.01) stats(N_h_l N_h_r, fmt(%9.0f) label(Eff. Number of obs)) style(tex)
	
			**C) Standardized English Scores
			
bys newID: egen thirdyearEng = mean(English) if Exam==31 | Exam==32 | Exam==33 | Exam==34 | Exam==35 | Exam==36 | Exam==37  
	
		egen steng111sci = std(thirdyearEng) if year==2015 & Division==1
		egen steng211sci = std(thirdyearEng) if year==2016 & Division==1
		egen steng311sci = std(thirdyearEng) if year==2017 & Division==1
		
		
		egen steng111art = std(thirdyearEng) if year==2015 & Division==0
		egen steng211art = std(thirdyearEng) if year==2016 & Division==0
		egen steng311art = std(thirdyearEng) if year==2017 & Division==0
		
		gen stenglish3 = steng111sci 
		replace stenglish3 = steng211sci if year==2016 & Division==1
		replace stenglish3 = steng311sci if year==2017 & Division==1
		
		replace stenglish3 = steng111art if year==2015 & Division==0
		replace stenglish3 = steng211art if year==2016 & Division==0
		replace stenglish3 = steng311art if year==2017 & Division==0
		
			
						*Triangular CCT without controls*		
		rdrobust  stenglish3 normrunning if Exam==31 & hsscore!=.,  h(  52.858      23.685)
				estimates store reg1

		*Uniform CCT without controls*		
		rdrobust  stenglish3 normrunning if Exam==31 & hsscore!=.,  h(   52.858      23.685) kernel(uni)
				estimates store reg2

		
		
		*Triangular CCT with controls*(use this to pick bandwidths)	
		rdrobust  stenglish3 normrunning if Exam==31 & hsscore!=., covs(sex years1 years2 hsscore urban) bwselect ( msetwo )
				estimates store reg3

		*Uniform CCT with controls*		
		rdrobust  stenglish3 normrunning if Exam==31 & hsscore!=., covs(sex years1 years2 hsscore urban ) h(  52.858      23.685) kernel(uni)
		estimates store reg4

		
		
				estout reg* using test.tex, replace cells(b(fmt(%9.3f) star label(Coef.)) se(fmt(%9.3f) par label(Std)))  starlevels(* 0.1 ** 0.05 *** 0.01) stats(N_h_l N_h_r, fmt(%9.0f) label(Eff. Number of obs)) style(tex)
		
		
		
	
	
						*****************************************************************************************************************************************
					    ********************************************************Table 4---Long Run Outcomes***************************************************************
						*****************************************************************************************************************************************
	
	*A) Standardized GAOKAO EXAM RESULTS
  
	
	**Without controls**
	
rdrobust stgaok  normrunning if Exam==99 & hsscore!=.,  h(   57.612      22.614)	
	estimates store reg1

	rdrobust stgaok  normrunning if Exam==99 & hsscore!=.,	kernel(uniform) h(    57.612      22.614)
		estimates store reg2

	
		**With controls** Use this one to decide bandwidth
	
rdrobust stgaok  normrunning if Exam==99 & hsscore!=., covs(sex years1 years2 hsscore urban) bwselect ( msetwo )	
	estimates store reg3

	rdrobust stgaok  normrunning if Exam==99 & hsscore!=., covs(sex years1 years2 hsscore urban)	kernel(uniform) h(  57.612      22.614)
		estimates store reg4

	
	**LATE ESTIMATE WITH CONTROLS*
			rdrobust stgaok  normrunning if Exam==99 & hsscore!=., covs(sex years1 years2 hsscore urban)	 fuzzy (Top_class1)  h(   57.612      22.614)
				estimates store reg5

		rdrobust stgaok  normrunning if Exam==99 & hsscore!=., covs(sex years1 years2 hsscore urban)	kernel(uniform) fuzzy (Top_class1)  h(  57.612      22.614)
			estimates store reg6

		
		
				estout reg* using test.tex, replace cells(b(fmt(%9.3f) star label(Coef.)) se(fmt(%9.3f) par label(Std)))  starlevels(* 0.1 ** 0.05 *** 0.01) stats(N_b_l N_b_r, fmt(%9.0f) label(Eff. Number of obs)) style(tex)
				
				estimates drop reg*
		
		
		
		*B) College attendance Outcomes 
						
						
**Without controls**
	
rdrobust  College1 normrunning if Exam==99 & hsscore!=.,  h(  44.428      20.877)
	estimates store reg1
	rdrobust  College1  normrunning if Exam==99 & hsscore!=.,	kernel(uniform) h(  44.428      20.877)	
		estimates store reg2

	
		**With controls** Use this one to decide bandwidth
	
rdrobust  College1 normrunning if Exam==99 & hsscore!=., covs(sex years1 years2 hsscore urban) bwselect ( msetwo )	
	estimates store reg3

	rdrobust  College1 normrunning if Exam==99 & hsscore!=., covs(sex years1 years2 hsscore urban)	kernel(uniform) h(  44.428      20.877)
		estimates store reg4

	
	**LATE ESTIMATE WITH CONTROLS*
			rdrobust  College1  normrunning if Exam==99 & hsscore!=., covs(sex years1 years2 hsscore urban)	 fuzzy (Top_class1)  h( 44.428      20.877)	
				estimates store reg5

		rdrobust  College1  normrunning if Exam==99 & hsscore!=., covs(sex years1 years2 hsscore urban)	kernel(uniform) fuzzy (Top_class1)  h( 44.428      20.877)	
			estimates store reg6


		
				estout reg* using test.tex, replace cells(b(fmt(%9.3f) star label(Coef.)) se(fmt(%9.3f) par label(Std)))  starlevels(* 0.1 ** 0.05 *** 0.01) stats(N_b_l N_b_r, fmt(%9.0f) label(Eff. Number of obs)) style(tex)
				
				estimates drop reg*

		
		
		
		*C) First tier Univisty attendance (widest definition)
		gen firsttieradmit = 1 if if_FirstBatch==1
		replace firsttieradmit = 0 if if_FirstBatch!= 1

     **Without controls**
	
     rdrobust firsttieradmit normrunning if Exam==99 & hsscore!=.,  h(   36.579      23.386)
	estimates store reg1
	rdrobust firsttieradmit  normrunning if Exam==99 & hsscore!=.,	kernel(uniform) h(   36.579      23.386)	
		estimates store reg2

	
		**With controls** Use this one to decide bandwidth
	
rdrobust firsttieradmit normrunning if Exam==99 & hsscore!=., covs(sex years1 years2 hsscore urban) bwselect ( msetwo )	
	estimates store reg3

	rdrobust firsttieradmit  normrunning if Exam==99 & hsscore!=., covs(sex years1 years2 hsscore urban )	kernel(uniform) h( 36.579      23.386)
		estimates store reg4

	
	**LATE ESTIMATE WITH CONTROLS*
			rdrobust firsttieradmit  normrunning if Exam==99 & hsscore!=., covs(sex years1 years2 hsscore urban )	 fuzzy (Top_class1)  h(   36.579      23.386)	
				estimates store reg5

		rdrobust firsttieradmit  normrunning if Exam==99 & hsscore!=., covs(sex years1 years2 hsscore urban )	kernel(uniform) fuzzy (Top_class1)  h(   36.579      23.386)	
			estimates store reg6


		
		
				estout reg* using test.tex, replace cells(b(fmt(%9.3f) star label(Coef.)) se(fmt(%9.3f) par label(Std)))  starlevels(* 0.1 ** 0.05 *** 0.01) stats(N_b_l N_b_r, fmt(%9.0f) label(Eff. Number of obs)) style(tex)
				
				estimates drop reg*
		
	**D) Top 100 (211 project) Univisty attendance (2nd widest definition)
*Fixing errors with 211 schools (those who didnt enter first_tier). This is instnce where someone is in top 100 but not intop tier (which shouldnt be possible)

**Without controls**
	
rdrobust top100admit normrunning if Exam==99 & hsscore!=.,  h(     50.601      22.827)	
	estimates store reg1

	rdrobust  top100admit  normrunning if Exam==99 & hsscore!=.,	kernel(uniform) h(    50.601      22.827)
		estimates store reg2

	
		**With controls** Use this one to decide bandwidth
	
rdrobust  top100admit normrunning if Exam==99 & hsscore!=., covs(sex years1 years2 hsscore urban ) bwselect ( msetwo )
	estimates store reg3
	
	rdrobust  top100admit  normrunning if Exam==99 & hsscore!=., covs(sex years1 years2 hsscore urban )	kernel(uniform) h(   50.601      22.827)	
		estimates store reg4

	
	**LATE ESTIMATE WITH CONTROLS*
			rdrobust  top100admit  normrunning if Exam==99 & hsscore!=., covs(sex years1 years2 hsscore urban )	 fuzzy (Top_class1)  h(   50.601      22.827)	
				estimates store reg5

		rdrobust  top100admit  normrunning if Exam==99 & hsscore!=., covs(sex years1 years2 hsscore urban )	kernel(uniform) fuzzy (Top_class1)  h(   50.601      22.827)
			estimates store reg6

		

				estout reg* using test.tex, replace cells(b(fmt(%9.3f) star label(Coef.)) se(fmt(%9.3f) par label(Std)))  starlevels(* 0.1 ** 0.05 *** 0.01) stats(N_b_l N_b_r, fmt(%9.0f) label(Eff. Number of obs)) style(tex)
				
				estimates drop reg*
		
	*E) Top 40 (985 project) Univisty attendance (2nd widest definition)
	
**Without controls**
	
rdrobust top40admit  normrunning if Exam==99 & hsscore!=.,  h(   44.606      19.614)	
	estimates store reg1

	rdrobust top40admit   normrunning if Exam==99 & hsscore!=.,	kernel(uniform) h(   44.606      19.614)
		estimates store reg2

	
		**With controls** Use this one to decide bandwidth
	
rdrobust top40admit  normrunning if Exam==99 & hsscore!=., covs(sex years1 years2 hsscore urban) bwselect ( msetwo )	
	estimates store reg3

	rdrobust top40admit   normrunning if Exam==99 & hsscore!=., covs(sex years1 years2 hsscore urban)	kernel(uniform) h(  44.606      19.614)	
		estimates store reg4

	
	**LATE ESTIMATE WITH CONTROLS*
			rdrobust top40admit   normrunning if Exam==99 & hsscore!=., covs(sex years1 years2 hsscore urban)	 fuzzy (Top_class1)  h(   44.606      19.614)	
				estimates store reg5

		rdrobust top40admit  normrunning if Exam==99 & hsscore!=., covs(sex years1 years2 hsscore urban)	kernel(uniform) fuzzy (Top_class1)  h(   44.606      19.614)
			estimates store reg6


		
				estout reg* using test.tex, replace cells(b(fmt(%9.3f) star label(Coef.)) se(fmt(%9.3f) par label(Std)))  starlevels(* 0.1 ** 0.05 *** 0.01) stats(N_b_l N_b_r, fmt(%9.0f) label(Eff. Number of obs)) style(tex)
				
				estimates drop reg*
		
	